#ifndef __IS_CORE_TRIANGLEBUFFER__
#define __IS_CORE_TRIANGLEBUFFER__

#include "../../MCD/Render/MeshBuilder.h"

namespace IS
{

class IS_CORE_API TriangleBuffer
	: protected MeshBuilder
	, public LinkListBase::Node<TriangleBuffer>
{
public:
	struct Vertex
	{
		Vec3f pos;
		Vec3f normal;
		Vec3f tangent;
		Vec4f color;
		Vec2f uv0;
		Vec2f uv1;
	};

public:
	TriangleBuffer();

	~TriangleBuffer();

	void beginDefine();

	void defineTriangle(int hash[3], Vertex vertex[3]);

	void endDefine();

	void beginUpdate();

	size_t getTriangleCount() const;

	uint16_t* getTriangleIndexAt(size_t face);

	Vec3f& getPositionAt(uint16_t vertexIndex);

	Vec3f& getNormalAt(uint16_t vertexIndex);
	
	Vec3f& getTangentAt(uint16_t vertexIndex);

	Vec2f& getUV0At(uint16_t vertexIndex);

	Vec2f& getUV1At(uint16_t vertexIndex);

	Vec4f& getColorAt(size_t vertexIndex);

	void endUpdate();

	void draw();

	Mat44f localTransform;

private:
	class Impl;
	Impl* mImpl;
};

}	// namespace IS

#endif	__IS_CORE_TRIANGLEBUFFER__